package com.huawei.weather.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.huawei.weather.domain.WeatherResponse;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.web.client.RestTemplate;

@Configuration
public class WebConfig {

    @Bean
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }


//    @Bean
//    public RedisTemplate  redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
//        RedisTemplate redisTemplate = new RedisTemplate<>();
//        redisTemplate.setConnectionFactory(lettuceConnectionFactory);
//
//        // 使用 Jackson2JsonRedisSerializer 进行序列化
//        Jackson2JsonRedisSerializer<WeatherResponse> serializer = new Jackson2JsonRedisSerializer<>(WeatherResponse.class);
//        ObjectMapper objectMapper = new ObjectMapper();
//        serializer.setObjectMapper(objectMapper);
//
//        redisTemplate.setValueSerializer(serializer);
//        return redisTemplate;
//    }

}
